// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Splats Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 73 : TYPE_SPLATS

// Function declarations
reserve function Splats_DebugDraw
reserve function Splats_DebugSpawn

// Static Values
public value Splats_value35 = 0;

// Tables

function Splats_DebugDraw
	temp0 = object[0].value17
	temp0 -= Splats_value35
	DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
end function


function Splats_DebugSpawn
	temp0 = object[0].value17
	temp0 -= Splats_value35
	temp0 <<= 1
	CreateTempObject(TypeName[Splats], temp0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].value1 = object.xpos
	object[tempObjectPos].value2 = object.ypos
	if object[tempObjectPos].direction == FLIP_NONE
		object[tempObjectPos].xvel = -0x10000
	else
		object[tempObjectPos].xvel = 0x10000
	end if
end function


event ObjectMain
	object.priority = PRIORITY_ACTIVE
	object.xpos += object.xvel
	object.ypos += object.yvel
	object.yvel += 0x3800
	if object.yvel > 0
		ObjectTileCollision(CSIDE_FLOOR, 0, 16, 0)
		temp0 = checkResult
		ObjectTileCollision(CSIDE_FLOOR, 0, 17, 0)
		temp0 |= checkResult
		ObjectTileCollision(CSIDE_FLOOR, 0, 18, 0)
		temp0 |= checkResult
		ObjectTileCollision(CSIDE_FLOOR, 0, 19, 0)
		temp0 |= checkResult
		ObjectTileCollision(CSIDE_FLOOR, 0, 20, 0)
		temp0 |= checkResult
		if temp0 == 1
			GetBit(temp0, object.propertyValue, 1)
			if temp0 == 1
				if object.value0 == 1
					FlipSign(object.xvel)
					object.direction ^= FLIP_X
				end if
				object.value0 ^= 1
			end if
			object.yvel = -0x40000
		end if
	end if
	if object.outOfBounds == 1
		temp0 = object.xpos
		temp1 = object.ypos
		object.xpos = object.value1
		object.ypos = object.value2
		if object.outOfBounds == 1
			GetBit(temp0, object.propertyValue, 0)
			if temp0 == 0
				object.direction = FLIP_NONE
				object.xvel = -0x10000
			else
				object.direction = FLIP_X
				object.xvel = 0x10000
			end if
			object.priority = PRIORITY_ACTIVE_BOUNDS
			object.state = 0
		else
			object.xpos = temp0
			object.ypos = temp1
		end if
	end if
	CallFunction(PlayerObject_EnemyPop)
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -10, -20, 6, 20, currentPlayer, object[currentPlayer].value40, object[currentPlayer].value38, object[currentPlayer].value41, object[currentPlayer].value39)
		if checkResult == 1
			CallFunction(PlayerObject_BadnikBreak)
		end if
	next
	foreach (TypeName[Bullet], arrayPos0, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -10, -20, 6, 20, arrayPos0, -6, -4, 6, 4)
		if checkResult == 1
			CallFunction(BulletKill)
		end if
	next	
end event


event ObjectDraw
	if object.yvel < 0
		DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
	else
		DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == 1
		LoadSpriteSheet("GHZ/Objects.gif")
		SpriteFrame(-11, -15, 21, 40, 214, 211)
		SpriteFrame(-11, -19, 21, 40, 192, 211)
	end if
	CheckCurrentStageFolder("BossRush")
	if checkResult == 1
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-11, -15, 21, 40, 220, 254)
		SpriteFrame(-11, -19, 21, 40, 198, 254)
	end if
	CheckCurrentStageFolder("Zone00")
	if checkResult == 1
		LoadSpriteSheet("GHZ/Objects3.gif")
		SpriteFrame(-11, -15, 21, 40, 220, 254)
		SpriteFrame(-11, -19, 21, 40, 198, 254)
	end if
	foreach (TypeName[Splats], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].xpos
		object[arrayPos0].value2 = object[arrayPos0].ypos
		GetBit(temp0, object[arrayPos0].propertyValue, 0)
		if temp0 == 0
			object[arrayPos0].direction = FLIP_NONE
			object[arrayPos0].xvel = -0x10000
		else
			object[arrayPos0].direction = FLIP_X
			object[arrayPos0].xvel = 0x10000
		end if
	next
	temp0 = 0
	Splats_value35 = DebugMode_ObjCount
	while temp0 < 2
		SetTableValue(TypeName[Splats], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(Splats_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(Splats_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
